Getting started
Development for the Centurion app requires Nodejs, Vue, PrimeVue, GitHub, and Postgres. The current setup has been using Visual Studio Code as the editor for all three repos.
Nodejs
Install and use the Nodejs version listed in the centurionV2-workers package.json file. Centurion to date has not been tested with a higher version but it should work fine.
Vue and PrimeVue
The Vue framework and the Vue component framework will be installed into the project centurionV2-vue.
Postgres
Before attempting development you must have Postgres v16 installed locally. For Mac developers the easiest option is to use the Postgres.app. Use the graphical interface and create a database named centurionv2. The database is expected to be running at DB_CONNECTION=postgres://127.0.0.1:5432/centurionv2.
- Open the Postgres app.
- Double click the
postgresdatabase icon to open a terminal.
- Enter the create database command.
create database centurionv2;
- Close the current terminal connected to the
postgresdatabase. - Double click the
centurionv2database icon to open a terminal for the newcenturionv2database which should display acenturionv2=#prompt.
- Run the create-db.sql script. You will need to adjust the path if it differs from below.
\i ~/DEV/centurionV2/centurionV2-nodejs/database/create-db.sql;
GitHub
Two repos that make up the Centurion app are hosted on GitHub.
Keybase
.env files are stored on Keybase and can be shared with anyone needing to work on the Centurion codebase. Each repo has its own .env file. They can be found under the api3_centurion team.
centurionV2-workers
This project runs independently of the other two projects. Its purpose is to gather external data (on and off-chain) to populate the database with the data centurionV2-nodejs needs to feed the frontend centurionV2-vue.
Clone the repo, cd into the project, then run yarn --ignore-engines install. The --ignore-engines flag is important because the dapi-manangement package may try to enforce a different version of Node.js as declared in package.json.
git clone git@github.com:api3dao/centurionV2-workers.git
cd centurionV2-workers
yarn --ignore-engines install
The .env file will not be present in the cloned repo. Access it on Keybase. It can be found under the api3_centurion team.
There are two start scripts where start is generally for the production system on Heroku and requires the the environment variable NODE_ENV be setup using its UI.
"start-dev": "NODE_ENV=development DEBUG=cent:* node ./bin/www",
"start": "DEBUG=cent:* node ./bin/www"
Be sure the local Postgres centurion database is running, then start the project. Start the project using yarn start-dev or yarn start-dev-inspect where the latter will sent messages to the chrome inspector.
yarn start-dev
# OR add the chrome inspector
yarn start-dev --inspect
## output
yarn run v1.22.19
$ NODE_ENV=development DEBUG=cent:* node index.js
|----------------------------------------------------|
| centurionV2-workers: 2.1.2
| NODE_ENV: development
| Nodejs vrs: v20.10.0
| GENERATE_ALERTS: ON
| port: 8088
| DB_CONNECTION: postgres://127.0.0.1:5432/centu...
| Memory at startup completion:
| rss 43.25 MB
| heapTotal 9.48 MB
| heapUsed 6.24 MB
| external 2.15 MB
| arrayBuffers 0.02 MB
|----------------------------------------------------|
cent:postgres Postgres pool DB_CONNECTION: postgres://127.0.0.1:5432/centurionv2 +0ms
cent:postgres Test call: { now: 2024-04-12T15:52:33.224Z } +155ms
Once started there will be console output showing the different workers that run on a regular basis.
TTL: 282.279ms
FEEDS sync: 2.233s
CHAINS sync: 5.856s
PRICES sync: 6.458s
SYMBOLS sync: 12.347s
PRICES sync: 6.442s
OPERATIONS sync: 5:50.205 (m:ss.mmm)
...
centurionV2-nodejs
This project reads data from the database and serves it to the app centurionV2-vue. Additionally if runs the sycHistory process every minute. This process checks data in the database against API providers using Axios for feed/chain pairs that may be out of deviation.
Clone the repo, cd into the project, then run yarn install.
git clone git@github.com:api3dao/centurionV2-nodejs.git
cd centurionV2-nodejs
yarn install
The .env file will not be present in the cloned repo. Access it on Keybase. It can be found under the api3_centurion team.
There are two start scripts where start is generally for the production system on Heroku and requires the the environment variable NODE_ENV be setup using its UI. The development scriptstart-dev requires the environment variable MIN_APP_VERSION to be defined if working on the code that tells the frontend to update itself, see Force app update for more information.
"start-dev": "NODE_ENV=development DEBUG=cent:* node --inspect ./bin/www",
"start": "DEBUG=cent:* node ./bin/www"
Start the project using yarn start-dev or yarn start-dev-inspect where the latter will sent messages to the chrome inspector.
yarn start-dev
## output
yarn run v1.22.19
$ NODE_ENV=development DEBUG=cent:* node ./bin/www
|-------------------------------------------------------|
| centurionV2-nodejs 2.1.2
| NODE_ENV: development
| DB_CONNECTION: postgres://127.0.0.1:5432/centurionv2
| MIN_APP_VERSION: undefined
| Nodejs vrs: v20.10.0
| GENERATE_ALERTS: OFF
| WARNING
| process.env.GENERATE_ALERTS is turned OFF
|-------------------------------------------------------|
cent:postgres Postgres pool DB_CONNECTION: postgres://127.0.0.1:5432/centurionv2 +0ms
cent:server Listening on port 3000-6::::3000 +0ms
cent:postgres Test call: { now: 2024-04-12T15:53:23.050Z } +193ms
...
centurionV2-vue
This project is the frontend and reads/updates using REST endpoints in centurionV2-nodejs.
Clone the repo, cd into the project, then run yarn install.
git clone git@github.com:api3dao/centurionV2-vue.git
cd centurionV2-vue
yarn install
The .env.development and .env.production files will not be present in the cloned repo. Access them on Keybase. They can be found under the api3_centurion team.
There is only one script used to start the app. Vite is used to run the Vue framework.
"dev": "vite",
Start the project using yarn dev. Optionally use the --host parameter if you wish to allow other devices to access the app on the local network such as a mobile device. The parameter will publish the app on the host's local IP in addition to localhost.
If you work on both airnode-docs and centurionV2-vue you will find it useful to use a different port other than 5173. There is an issue where VitePress injects a theme field into localstorage that gets picked up by centurionV2-vue causing issues with its login and logout process.
yarn dev --host
# OR
yarn dev --host --port 7005
## output
VITE v4.4.9 ready in 117 ms
➜ Local: http://localhost:5173/
➜ Network: http://192.168.1.12:5173/
➜ press h to show help
...